from openai import OpenAI
from langchain.chat_models import ChatOpenAI
from langchain.schema import SystemMessage,HumanMessage
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

model = ChatOpenAI(
    model="gpt-3.5-turbo",
    temperature=0.3,
    max_tokens=500,
    api_key="hk-mtiquv1000041663a49a34520ad3294132cbce7abf1c2ef3",
    base_url="https://api.openai-hk.com/v1"
)
# response = chat.invoke('中国的首都是哪里？不需要介绍')
# from langchain_core.output_parsers import StrOutputParser
# output_sparser = StrOutputParser()
# print(output_sparser.invoke(response))

# prompt | model | output_parser

prompt = ChatPromptTemplate.from_template("请根据下面的主题写一篇小红书营销短文：{topic}")
output_sparser = StrOutputParser()
chain = prompt | model | output_sparser
print(chain.invoke({"topic":"康师傅绿茶"}))